package com.ss.android.lockscreen.activity.lock;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ss.android.lockscreen.activity.lock.b.d;
import com.ss.android.lockscreen.activity.lock.b.g;
import com.ss.android.lockscreen.activity.lock.b.h;
import com.ss.android.lockscreen.activity.lock.b.i;
import com.ss.android.lockscreen.http.data.ScreenCell.Type;
import com.ss.android.lockscreen.http.data.ScreenCell;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Stack;

public final class w extends PagerAdapter {
    public interface a {
        void a(ScreenCell arg1);

        void a(View arg1, ScreenCell arg2);
    }

    public interface b {
        void a();
    }

    b a;
    List b;
    a c;
    private LayoutInflater d;
    private Stack[] e;
    private List f;
    private Context g;
    private boolean h;
    private int i;

    w(Context arg5) {

        this.a = null;
        this.h = true;
        this.i = 0;
        this.d = LayoutInflater.from(arg5);
        this.f = new ArrayList();
        switch (android.support.design.a.B.e()) {
            case 2: {
                this.f.add(0, d.class);
                this.f.add(1, h.class);
                this.f.add(2, i.class);
                break;
            }
            default: {
                this.f.add(0, com.ss.android.lockscreen.activity.lock.b.aa.class);
                this.f.add(1, g.class);
                break;
            }
        }

        this.g = arg5;
        this.e = new Stack[this.f.size()];
    }

    public final int getCount() {
        int v0 = 1;
        if (this.b != null && this.b.size() != 0) {
            int v1 = this.b.size();
            if (!this.h) {
                v0 = 0;
            }

            v0 += v1;
        }

        return v0;
    }

    final void a(List arg3, boolean arg4) {
        this.h = arg4;
        if (this.b == null) {
            this.b = new ArrayList();
        }

        this.b.addAll(((Collection) arg3));
        this.c(this.b.size() - arg3.size());
        if (this.a != null) {
            this.a.a();
        }
    }

    public final int getItemPosition(Object arg4) {
        int v0_1;
        int v1 = -2;
        if ((arg4 instanceof com.ss.android.lockscreen.activity.lock.b.a.a)) {
            Object v0 = ((com.ss.android.lockscreen.activity.lock.b.a.a) arg4).a().getTag(com.ss.android.article.browser.R.id.ai);
            if (!(v0 instanceof Integer)) {
                v0_1 = v1;
            } else if (((Integer) v0).intValue() < this.i) {
                v0_1 = -1;
            } else {
                v0_1 = v1;
            }
        } else {
            v0_1 = v1;
        }

        return v0_1;
    }

    public final Object instantiateItem(ViewGroup arg6, int arg7) {
        Object v1_3;
        LayoutInflater v1_1;
        Object v2 = null;
        int v3 = this.d(arg7);
        Object v0 = this.f.get(v3);
        if (v0 != null) {
            Stack v1 = this.e[v3];
            if (v1 == null) {
                v1 = new Stack();
                this.e[v3] = v1;
            }

            if (v1.isEmpty()) {
                try {
                    v0 = ((Class) v0).newInstance();
                    v1_1 = this.d;
                } catch (Exception v0_1) {
                    return v2;
                }

                View v1_2 = ((com.ss.android.lockscreen.activity.lock.b.a.a) v0).a(v1_1, arg6, this.g);
                v1_2.setTag(v0);
                v1_2.setTag(com.ss.android.article.browser.R.id.aj, Integer.valueOf(v3));
            } else {
                v0 = v1.pop();
            }

            ((com.ss.android.lockscreen.activity.lock.b.a.a) v0).a().setTag(com.ss.android.article.browser.R.id.ai, Integer.valueOf(arg7));
            ((com.ss.android.lockscreen.activity.lock.b.a.a) v0).a(this.c);
            switch (this.d(arg7)) {
                case 0: {
                    v1_3 = this.b.get(arg7);
                    break;
                }
                case 2: {
                    v1_3 = this.b.get(arg7);
                    break;
                }
                default: {
                    v1_3 = v2;
                    break;
                }
            }

            ((com.ss.android.lockscreen.activity.lock.b.a.a) v0).a(v1_3);
            arg6.addView(((com.ss.android.lockscreen.activity.lock.b.a.a) v0).a());
            v2 = v0;
        }

        return v2;
    }

    public final void destroyItem(ViewGroup arg4, int arg5, Object arg6) {
        if ((arg6 instanceof com.ss.android.lockscreen.activity.lock.b.a.a)) {
            Object v0 = ((com.ss.android.lockscreen.activity.lock.b.a.a) arg6).a().getTag(com.ss.android.article.browser.R.id.aj);
            if ((v0 instanceof Integer)) {
                int v1 = ((Integer) v0).intValue();
                Stack v0_1 = this.e[v1];
                if (v0_1 == null) {
                    v0_1 = new Stack();
                    this.e[v1] = v0_1;
                }

                v0_1.push(arg6);
            }

            arg4.removeView(((com.ss.android.lockscreen.activity.lock.b.a.a) arg6).a());
        }
    }

    public final boolean isViewFromObject(View arg2, Object arg3) {
        boolean v0 = !(arg3 instanceof com.ss.android.lockscreen.activity.lock.b.a.a) || ((com.ss.android.lockscreen.activity.lock.b.a.a) arg3).a() != arg2 ? false : true;
        return v0;
    }

    final ScreenCell b(int arg2) {
        ScreenCell v0_1;
        if (this.b == null || arg2 < 0 || arg2 >= this.b.size()) {
            v0_1 = null;
        } else {
            v0_1 = (ScreenCell) this.b.get(arg2);
        }

        return v0_1;
    }

    final void c(int arg1) {
        this.i = arg1;
        super.notifyDataSetChanged();
    }

    public final void notifyDataSetChanged() {
        this.i = 0;
        super.notifyDataSetChanged();
    }

    final int d() {
        int v0 = this.b == null ? 0 : this.b.size();
        return v0;
    }

    private int d(int arg4) {
        int v0;
        if (arg4 == this.getCount() - 1) {
            v0 = 1;
        } else {
            if (this.b != null && arg4 < this.b.size() && this.b.get(arg4) != null) {
                Type v0_1 = ((ScreenCell) this.b.get(arg4)).b;
                if (v0_1 == Type.LittleVideo) {
                    return 2;
                } else if (v0_1 == Type.Feed) {
                    return 0;
                }
            }

            v0 = 1;
        }

        return v0;
    }
}

